<?php defined('InNcPHP') or exit('Access Invalid!');?>

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3><?php echo $lang['advert_index'];?></h3>
            <?php echo $output['top_link'];?>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <form method="post" id='form_advert'>
        <input type="hidden" name="form_submit" value="ok" />
        <table class="table tb-type2">
            <thead>
            <tr class="space">
                <th colspan="15" class="nobg"><?php echo $lang['nc_list'];?></th>
            </tr>
            <tr class="thead">
                <th><?php echo $lang['nc_common_select'];?></th>
                <th class="align-center"><?php echo $lang['advert_index_advert_name'];?></th>
                <th class="align-center"><?php echo $lang['advert_index_advert_type'];?></th>
                <th class="align-center"><?php echo $lang['advert_sort'];?></th>
                <th class="align-center"><?php echo $lang['advert_index_advert_url'];?></th>
                <th class="align-center"><?php echo $lang['advert_index_advert_image'];?></th>
                <th class="align-center"><?php echo $lang['advert_index_state'];?></th>
                <th class="align-center"><?php echo $lang['advert_index_addtime'];?></th>
                <th class="align-center"><?php echo $lang['nc_handle'];?></th>
            </tr>
            </thead>
            <tbody>
            <?php if(!empty($output['list']) && is_array($output['list'])){ ?>
                <?php foreach($output['list'] as $k => $v){ ?>
                    <tr class="hover">
                        <td class="w24">
                            <input name="del_id[]" type="checkbox" value="<?php echo $v['advert_id']; ?>" class="checkitem" onclick="javascript:chkRow(this);">
                        </td>
                        <td class="align-center"><?php echo $v['advert_name']; ?></td>
                        <td class="align-center"><?php echo $output['advert_type_list'][$v['advert_type']]; ?></td>
                        <td class="align-center"><?php echo $v['advert_sort']; ?></td>
                        <td class="align-center" ><?php echo $v['advert_url'];?></td>
                        <td class="align-center" ><img src="<?php echo UPLOAD.'product/'.$v['advert_image'];?>" style="width: 160px;height: 80px;"></td>
                        <td class="align-center"><?php echo $v['state']==1?$lang['nc_common_enable']:$lang['nc_common_disable']?></td>
                        <td class="align-center"><?php echo date('Y-m-d H:i:s',$v['advert_time']); ?></td>
                        <td class="w150 align-center">
                            <a href="javascript:void(0)" onclick="confirmAble(<?php echo $v['advert_id']; ?>, <?php echo $v['state']==1?0:1; ?>);"><?php echo $v['state']==1?$lang['nc_common_disable']:$lang['nc_common_enable']?></a>
                            | <a href="javascript:void(0)" onclick="confirmDel(<?php echo $v['advert_id']; ?>);"><?php echo $lang['nc_delete'];?></a>
                            | <a href="index.php?act=advert&op=advert_edit&advert_id=<?php echo $v['advert_id']; ?>"><?php echo $lang['nc_edit'];?></a>
                        </td>
                    </tr>
                <?php } ?>
            <?php }else { ?>
                <tr class="no_data">
                    <td colspan="10"><?php echo $lang['nc_no_record'];?></td>
                </tr>
            <?php } ?>
            </tbody>
            <tfoot>
            <?php if(!empty($output['list']) && is_array($output['list'])){ ?>
                <tr class="tfoot">
                    <td><input type="checkbox" class="checkall" id="checkallBottom" name="chkVal"></td>
                    <td colspan="16"><label for="checkallBottom"><?php echo $lang['nc_select_all']; ?></label>
                        &nbsp;&nbsp;<a href="JavaScript:void(0);" class="btn" onclick="confirmDelAll();"><span><?php echo $lang['nc_del'];?></span></a>
                        <div class="pagination"> <?php echo $output['page'];?> </div></td>
                </tr>
            <?php } ?>
            </tfoot>
        </table>
    </form>
</div>
<script>
    function confirmAble(id, state) {
        var text = state?'<?php echo $lang['nc_common_enable']; ?>':'<?php echo $lang['nc_common_disable']; ?>';
        layer.confirm(text, {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        }, function (index) {
            location.href = 'index.php?act=advert&op=advert_update&advert_id='+id+'&state='+state;
        });
    }

    function confirmDel(id) {
        var text = '<?php echo $lang['nc_ensure_del'];?>';
        layer.confirm(text, {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        }, function (index) {
            location.href = 'index.php?act=advert&op=advert_del&advert_id='+id;
        });
    }

    function confirmDelAll() {
        var inputs = $('input[name="del_id[]"]:checked')
        var ids = [];
        inputs.each(function (i) {
            ids.push(this.value);
        });
        //校验选项是否为空
        if (ids.length < 1) {
            layer.alert('<?php echo $lang['nc_common_select']; ?>');
            return;
        }

        var text = '<?php echo $lang['nc_ensure_del'];?>';
        layer.confirm(text, {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        }, function (index) {
            $('#form_advert').submit();
        });
    }
</script>